package org.example.springmybatisdemo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.example.springmybatisdemo.entity.*;
import org.example.springmybatisdemo.service.EmpServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "职工管理")
@RequestMapping("/api/emps")
@RestController
public class EmpController {
    @Resource(name = "empServiceImpl")
    private EmpServiceImpl empService;

    Logger log = LoggerFactory.getLogger("com.foo");
    //    分页插件
    @Operation(summary = "职工列表")
    @GetMapping("/emppage")
    public  Result<PageBean> listpluginpage(
            EmpQueryParam param
    ) {
        //        1. 调用service获取数据
//        List<Emp> deptlist = empService.emplist(page, pageSize);
//        log.info(deptlist.toString());
        log.info("emp进来了 请求参数"+param.toString());
        //        2. 响应数据
        PageBean pagebean = empService.pagelist(param);
        return Result.success(pagebean) ;
    }

//    新增员工
@Operation(summary = "新增职工")
    @PostMapping("/addemp")
    public Result<Integer> addEmp(@RequestBody Emp emp) {
        log.info("emp进来了 添加员工"+emp.toString());
        // 调用服务层并获取结果
        boolean success = empService.addEmp(emp);
//        if (add > 0) {
//            return Result.success();
//        }
        if (success) {
            // 返回成功响应，包含生成的ID
            return Result.success(emp.getId());
        } else {
            return Result.fail("添加失败", 400);
        }
    }
}
